<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>forEach循环方法</title>
    <style>
        .disable{
            color: #ccc;
        }
    </style>
</head>
<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>fskngs</li>
        <li>fdbdgsfh</li>
    </ul>
    <script>
        let lessons = [
            {lesson:"html",teacher:"Mr Lee"},
            {lesson:"css",teacher:"Mr Gao"},
            {lesson:"js",teacher:"Mr Liu"},
            {lesson:"php",teacher:"Mr Zhao"}
        ];

        // forEach的使用
        // lessons.forEach(function (item) {
        //     console.log(item);
        // });

        // lessons.forEach(function (item,index) {
        //     console.log(index);
        // });

        // lessons.forEach(function (item,index,lessons) {
        //     console.log(lessons);
        // });



        let lis = document.querySelectorAll("ul li");
        // 将dom节点转化为数组
        // console.log(Array.from(lis));
        // console.log([...lis]);

        // forEach可以直接操作dom元素
        lis.forEach(function (item) {
            item.addEventListener("click",function (params) {
                this.classList.toggle('disable');
            })
        })
    </script>
</body>
</html>